<%= render  :partial => "apo/navigation" %>

<div id="containerBody">

	<div style="margin-bottom: 0.5em">
		<% form_tag({:action => "list"}, {:style => "display: inline"}) do %>
			Showing:
			<% unless params[:filter].nil? %>
				<%= select "filter", "type",
				[
					["Active Members", nil],
					["All", "All"],
					["Actives", "Active"],
					["Pledges", "Pledge"],
					["New Actives", "New Active"],
					["Associates", "Associate"],
					["Probates", "Probate"],
					["Neophytes", "Neophyte"],
					["Away From School", "Away From School"],
					["Alums", "Alum"],
					["Advisors", "Advisor"]
				],
				{:selected => params[:filter][:type]},
				{:onchange => 'this.form.submit();'} %>
			<% else %>
				<%= select "filter", "type",
				[
					["Active Members", nil],
					["All", "All"],
					["Actives", "Active"],
					["Pledges", "Pledge"],
					["New Actives", "New Active"],
					["Associates", "Associate"],
					["Probates", "Probate"],
					["Neophytes", "Neophyte"],
					["Away From School", "Away From School"],
					["Alums", "Alum"],
					["Advisors", "Advisor"]
				],
				{},
				{:onchange => 'this.form.submit();'} %>
			<% end %>
		<% end %>
		<% if session[:user].admin? %>
			<% form_tag({:action => "create" , :id => params[:id]}, {:style => "display: inline"}) do %>
				<%= submit_tag "Create New Member" %>
			<% end %>
		<% end %>
	</div>

	<div class="container memberContainer">

		<div class="cellRow cellRowHeader">
			<div class="cellBlock">
				#
			</div>
			<div class="cellBlock">
				<%= link_to "Name" , :action => "list" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Service Points" , :action => "list", :sort_by => "service_hours" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Leadership Points" , :action => "list", :sort_by => "leaderships" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Fellowship Points" , :action => "list", :sort_by => "fellowships" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Meeting Points" , :action => "list", :sort_by => "active_meeting" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Fundraising Points" , :action => "list", :sort_by => "fundraisers" %>
			</div>
			<div class="cellBlock">
				<%= link_to "Dues" , :action => "list", :sort_by => "dues" %>
			</div><!--
			<div class="cellBlock">
				link_to "% Done" , :action => "list", :sort_by => "percent_done"
			</div>-->
			<% if session[:user].admin? %>
			<div class="cellBlock">
				&nbsp;
			</div>
			<% end %>
		</div>

		<% x = 1 %>
		<% service_hours = 0 %>
		<% leaderships = 0 %>
		<% fellowships = 0 %>
		<% meetings = 0 %>
		<% fundraisers = 0 %>
		<% dues = 0 %>

		<% @members.each do |member| %>
			<% memberData = Member.getData(member, Event.getCurrentSemester) %>
			<div class="cellRow cellRow<%= (x%2==0)?1:2 %> highlightRow">

				<% if member.status == "Active" or member.status == "New Active" or member.status == "Associate" or member.status == "Probate" %>
					<div class="cellBlock" style="text-align: right;">
						<%= x %>
					</div>
					<div class="cellBlock" style="text-align: left;">
						<%= link_to h(member.last_first) , :action => "show" , :id => member %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["service"]["actual"] %>/<%= memberData["total_required_hours"] %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["leadership"]["actual"].to_i %>/<%= Member.active_leaderships_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["fellowship"]["actual"].to_i %>/<%= Member.active_fellowships_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["meeting"]["actual"].to_i %>/<%= Member.active_meetings_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["fundraiser"]["actual"].to_i %>/<%= Member.active_fundraisers_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["dues"].to_i %>/<%= Member.active_dues_requirement %>
					</div>
					<!--
					<div class="cellBlock" style="text-align: center;">
						h memberData[9].to_i
					</div>-->
					<% if session[:user].admin? %>
						<div class="cellBlock">
							<%= link_to "x" , :action => "remove" , :id => member %>
						</div>
					<% end %>

				<% elsif member.status == "Pledge" or member.status == "Neophyte" %>
					<div class="cellBlock" style="text-align: right;">
						<%= x %>
					</div>
					<div class="cellBlock" style="text-align: left;">
						<%= link_to h(member.last_first) , :action => "show" , :id => member %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["service"]["actual"] %>/<%= memberData["total_required_hours"] %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["leadership"]["actual"].to_i %>/<%= Member.pledge_leaderships_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["fellowship"]["actual"].to_i %>/<%= Member.pledge_fellowships_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["meeting"]["actual"].to_i %>/<%= Member.pledge_meetings_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["fundraiser"]["actual"].to_i %>/<%= Member.pledge_fundraisers_requirement %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						<%=h memberData["dues"].to_i %>/<%= Member.pledge_dues_requirement %>
					</div>
					<!--
					<div class="cellBlock" style="text-align: center;">
						<%=h memberData[9].to_i %>
					</div>-->
					<% if session[:user].admin?  %>
						<div class="cellBlock">
							<%= link_to "x" , :action => "remove" , :id => member %>
						</div>
					<% end %>

				<% else %>
					<div class="cellBlock" style="text-align: right;">
						<%= x %>
					</div>
					<div class="cellBlock" style="text-align: left;">
						<%= link_to h(member.last_first) , :action => "show" , :id => member %>
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div><!--
					<div class="cellBlock" style="text-align: right;">
						&nbsp;
					</div>-->
					<% if session[:user].admin? %>
						<div class="cellBlock">
							<%= link_to "x" , :action => "remove" , :id => member %>
						</div>
					<% end %>
				<% end %>
			</div>

			<% if x%25 == 0 %>
			<div class="cellRow cellRowHeader">
				<div class="cellBlock">
					#
				</div>
				<div class="cellBlock">
					<%= link_to "Name" , :action => "list" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Service Points" , :action => "list", :sort_by => "service_hours" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Leadership Points" , :action => "list", :sort_by => "leaderships" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Fellowship Points" , :action => "list", :sort_by => "fellowships" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Meeting Points" , :action => "list", :sort_by => "active_meeting" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Fundraising Points" , :action => "list", :sort_by => "fundraisers" %>
				</div>
				<div class="cellBlock">
					<%= link_to "Dues" , :action => "list", :sort_by => "dues" %>
				</div><!--
				<div class="cellBlock">
					link_to "% Done" , :action => "list", :sort_by => "percent_done"
				</div>-->
				<% if session[:user].admin? %>
				<div class="cellBlock">
					&nbsp;
				</div>
				<% end %>
			</div>
			<% end %>

			<% member.up_to_date = true %>
			<% member.save %>

			<% x = x + 1 %>

			<% if "don't" == "do this" %>
				<% service_hours = service_hours + member.service_hours %>
				<% fellowships = fellowships + member.fellowships %>
				<% leaderships = leaderships + member.leaderships %>
				<% fundraisers = fundraisers + member.fundraisers %>
				<% if (member.status == "Pledge")%>
					<% meetings = meetings + member.pledge_meetings_attended + member.active_meetings_attended %>
				<% else %>
					<% meetings = meetings + member.active_meetings_attended %>
				<% end %>
			<% end %>

		<% end %>

		<% if "don't" == "do this too" %>
		<div class="cellRow cellRowHeader">

			<div class="cellBlock">

			</div>
			<div class="cellBlock">
				Totals
			</div>
			<div class="cellBlock">
				<%= service_hours %>
			</div>
			<div class="cellBlock">
				<%= fellowships %>
			</div>
			<div class="cellBlock">
				<%= leaderships %>
			</div>
			<div class="cellBlock">
				<%= fundraisers %>
			</div>
			<div class="cellBlock">

			</div>
			<div class="cellBlock">
				<%= office_hours %>
			</div>
			<div class="cellBlock">

			</div>
			<div class="cellBlock">

			</div>
			<div class="cellBlock">

			</div>
			<div class="cellBlock">

			</div>
			<div class="cellBlock">

			</div>
			<% if session[:user].admin? %>
			<div class="cellBlock">

			</div>
			<% end %>

		</div>
		<% end %>

	</div>

	<div id="eventBottomDiv" style="text-align: left;">
		<% if params[:filter] != nil %>
			<h3> <%= params[:filter][:type]%> Email List: </h3>
			<% @members.each do |member| %>
				<%= member.email %>,
			<% end %>
		<% else %>
			<h3> Email List: </h3>
			<% @members.each do |member| %>
				<%= member.email %>,
			<% end %>
		<% end %>
	</div>

</div>
